<?php

namespace App\Http\Resources\posts;

use App\Models\posts\UserFollow;
use Illuminate\Http\Resources\Json\ResourceCollection;

class FansPageCollection extends ResourceCollection
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {

        return [
            'total' => $this->resource->total(),
            'perPage' => $this->resource->perPage(),
            'current_page' => $this->resource->currentPage(),
            'items' => $this->collection->map(function (UserFollow $item) {
                return [
                    'id' => $item->id,
                    'updated_at' => $item->updated_at->toDateTimeString(),
                    'user' => [
                        'id' => $item->user->id,
                        'name' => $item->user->name,
                        'uuid' => $item->user->uuid,
                        'header_img' => $item->user->header_img,
                        'sex' => $item->user->sex,
                        'cate' => $item->user->cate,
                        'level' => $item->user->level,
                        'age' => $item->user->age,
                        'brief' => $item->user->brief??'',
                        'school' => $item->user->school??'',
                        'birthday' => $item->user->birthday??''
                    ]
                ];
            })
        ];

    }
}
